package yaner.hotel.manager.resource.mapper.impl;

import org.springframework.stereotype.Component;
import yaner.hotel.manager.common.dto.order.OrderAddDto;
import yaner.hotel.manager.common.dto.order.OrderUpdateDto;
import yaner.hotel.manager.common.utils.SnowUtils;
import yaner.hotel.manager.common.vo.OrderVo;
import yaner.hotel.manager.resource.entity.Order;
import yaner.hotel.manager.resource.mapper.IOrderMapper;

import java.util.Date;
import java.util.Objects;

@Component
public class OrderMapperImpl implements IOrderMapper {
    @Override
    public OrderVo toVo(Order order) {
        Objects.requireNonNull(order, "OrderMapperImpl toVo order is null");
            return OrderVo.builder()
                    .orderId(order.getOrderId())
                    .orderCode(order.getOrderCode())
                    .orderStatus(order.getOrderStatus())
                    .orderTypeStr(order.getOrderType().getDesc())
                    .orderType(order.getOrderType())
                    .customerName(order.getCustomerName())
                    .customerPhone(order.getCustomerPhone())
                    .userId(order.getUserId())
                    .orderDesc(order.getOrderDesc())
                    .paymentId(order.getPaymentId())
                    .paymentPrice(order.getPaymentPrice())
                    .paymentType(order.getPaymentType())
                    .paymentStatus(order.getPaymentStatus())
                    .build();
    }

    @Override
    public Order toAddEntity(OrderAddDto orderAddDto) {
        Objects.requireNonNull(orderAddDto, "OrderMapperImpl toAddEntity orderAddDto is null");
            return Order.builder()
                    .orderId(SnowUtils.nextId())
                    .orderCode(orderAddDto.getOrderCode())
                    .orderType(orderAddDto.getOrderType())
                    .orderStatus(orderAddDto.getOrderStatus())
                    .customerName(orderAddDto.getCustomerName())
                    .customerPhone(orderAddDto.getCustomerPhone())
                    .roomId(orderAddDto.getRoomId())
                    .paymentId(orderAddDto.getPaymentId())
                    .paymentType(orderAddDto.getPaymentType())
                    .paymentStatus(orderAddDto.getPaymentStatus())
                    .paymentPrice(orderAddDto.getPaymentPrice())
                    .customerSex(orderAddDto.getCustomerSex())
                    .occupancy(orderAddDto.getOccupancy())
                    .customerIdCardNo(orderAddDto.getCustomerIdCardNo())
                    .userId(orderAddDto.getUserId())
                    .orderDesc(orderAddDto.getOrderDesc())
                    .createTime(new Date())
                    .updateTime(new Date())
                    .paymentId(orderAddDto.getPaymentId())
                    .build();
    }

    @Override
    public Order toUpdateEntity(OrderUpdateDto orderUpdateDto) {
        Objects.requireNonNull(orderUpdateDto, "OrderMapperImpl toUpdateEntity orderUpdateDto is null");
            return Order.builder()
                    .orderId(orderUpdateDto.getOrderId())
                    .orderCode(orderUpdateDto.getOrderCode())
                    .orderStatus(orderUpdateDto.getOrderStatus())
                    .customerName(orderUpdateDto.getCustomerName())
                    .customerPhone(orderUpdateDto.getCustomerPhone())
                    .userId(orderUpdateDto.getUserId())
                    .orderDesc(orderUpdateDto.getOrderDesc())
                    .updateTime(new Date()).build();
    }
}
